import { Body, Controller, Delete, Get, Param, Post, Put, Patch } from '@nestjs/common'
import { AdminService } from './admin.service'
import { IsAdmin } from 'src/decorator/is-admin.decorator'
import { CreateAdminDto } from './dto/create-admin.dto'
import { AuthJWT } from 'src/decorator/auth.decorator'
import { GetUserInfo } from 'src/decorator/getUserInfo.decotator'
import { User } from '@prisma/client'

@Controller('admin')
export class AdminController {
   constructor(private readonly adminService: AdminService) {}

   @Get('/user/findall')
   findAllUser() {
      return this.adminService.findAllUser()
   }

   @Get('/user/count')
   findUserCount() {
      return this.adminService.findUserCount()
   }

   @Post('/login')
   login(@Body() data: CreateAdminDto) {
      return this.adminService.login(data)
   }

   @Get('/article/count')
   findArticleCount() {
      return this.adminService.getArticleByDay()
   }

   @AuthJWT()
   @Get('/current')
   getCurrentUser(@GetUserInfo() user: User) {
      return this.adminService.getCurrentUser(+user.id)
   }

   @AuthJWT()
   @Get('/commont/count')
   getCommontCount() {
      return this.adminService.getCommontCount()
   }

   @IsAdmin()
   @Delete('/user/:id')
   createAdmin(@Param('id') id: number) {
      return this.adminService.deleteUser(+id)
   }

   @IsAdmin()
   @Get('/user/findone/:username')
   findUserByUsername(@Param('username') username: string) {
      return this.adminService.findUserByUsername(username)
   }

   @IsAdmin()
   @Put('/user/:id')
   upUserStatus(@Param('id') id: number) {
      return this.adminService.upUserStatus(+id)
   }

   @IsAdmin()
   @Get('/article/findall')
   getArticleAll() {
      return this.adminService.getArticleAll()
   }

   @IsAdmin()
   @Patch('/article/:id/:status')
   changeStatus(@Param('id') id: number, @Param('status') status: number) {
      return this.adminService.changeStatus(+id, +status)
   }

   // 获取所有评论
   @IsAdmin()
   @Get('/commont/findall')
   getCommontAll() {
      return this.adminService.getAllCommont()
   }

   // 删除
   @IsAdmin()
   @Delete('/commont/:id')
   deleteCommont(@Param('id') id: number) {
      return this.adminService.deleteCommont(+id)
   }

   // 获取某个评论
   @IsAdmin()
   @Get('/commont/:id')
   getCommontById(@Param('id') id: number) {
      return this.adminService.getCommontById(+id)
   }

   // 根据用户名获取评论
   @IsAdmin()
   @Get('/commont/user/:username')
   getCommontByUser(@Param('username') username: string) {
      return this.adminService.getCommontByUserName(username)
   }
}
